package com.yuejian_06.yuejian_06.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;
import com.yuejian_06.yuejian_06.Listener.LoginListener;
import com.yuejian_06.yuejian_06.R;
import com.yuejian_06.yuejian_06.adapter.CoachVideoAdapter;
import com.yuejian_06.yuejian_06.bean.CoachVideoBean;
import com.yuejian_06.yuejian_06.fragment.Constants;
import com.yuejian_06.yuejian_06.fragment.Constants_l;
import com.yuejian_06.yuejian_06.model.CoachModel;

import java.util.List;

public class CoachInfoActivity extends BaseActivity {
    String coach_name,coach_id,coach_pic,coach_main;
    TextView coach_info_name,coach_info_main;
    ImageView coach_info_pic;
    ImageButton coach_info_back;
    Button btn1,btn2;
    RecyclerView recyclerView;

    private LoginListener<List<CoachVideoBean>> Listener=new LoginListener<List<CoachVideoBean>>() {
        @Override
        public void onResponse(List<CoachVideoBean> o) {
            List<CoachVideoBean> mDataList=o;
            recyclerView.setAdapter(new CoachVideoAdapter(CoachInfoActivity.this,mDataList));//设置适配器
        }
        @Override
        public void onFail(String msg) {
            Toast.makeText(getApplicationContext(),"失败了",Toast.LENGTH_SHORT).show();

        }
    };


    @Override
    void initViews() {
        setLayout(R.layout.activity_coach_info);
        Bundle bundle = getIntent().getExtras();
        coach_id = bundle.getString("coach_id");
        coach_pic=bundle.getString("coach_pic");
        coach_name=bundle.getString("coach_name");
        coach_main=bundle.getString("coach_main");
        coach_info_name=(TextView)findViewById(R.id.coach_info_name);
        coach_info_main=(TextView)findViewById(R.id.coach_info_main);
        coach_info_pic=(ImageView) findViewById(R.id.coach_info_pic);
        coach_info_back=(ImageButton) findViewById(R.id.coach_info_back);
        btn1=(Button)findViewById(R.id.coach_info_btn1);
        btn2=(Button)findViewById(R.id.coach_info_btn2);
        recyclerView = (RecyclerView)findViewById(R.id.coach_info_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(CoachInfoActivity.this));// 布局


        CoachModel coachModel=new CoachModel();
        coachModel.getcoachV(coach_id,Listener);
    }

    @Override
    void initEvents() {
        //返回按钮
        coach_info_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        //大师问答。
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                Intent intent=new Intent(CoachInfoActivity.this, CoachAnswerActivity.class);
                intent.putExtra("coach_id",coach_id);
                intent.putExtra("coach_name",coach_name);
                intent.putExtra("coach_pic",coach_pic);
                intent.putExtra("coach_main",coach_main);
                startActivity(intent);
            }
        });
    }

    @Override
    void initData() {
        coach_info_name.setText(coach_name);
        coach_info_main.setText(coach_main);
        String internetUrl = Constants.SSS+"yuejian/Public/coachPics/"+coach_pic;
        Picasso
                .with(CoachInfoActivity.this)
                .load(internetUrl)
                .into(coach_info_pic);}
    }
